<?php

class Pdfprinterlembur extends CI_Controller
{

	public function __construct(){
		parent::__construct();
		if(!Auth::isLoggedIn()) redirect("/");
		$this->load->model("model_pdf");
	}
	
	
	function index() 
	{	
		$this->pdfPrint();
	}


	function js_redirect($url, $seconds=1)
            { 
                echo "<script language=\"JavaScript\">\n"; 
                echo "<!-- hide from old browser\n\n";      
                echo "function redirect() {\n"; 
                echo "window.location = \"" . $url . "\";\n"; 
                echo "}\n\n"; 
                echo "timer = setTimeout('redirect()', '" . ($seconds*1000) . "');\n\n"; 
                echo "-->\n"; 
                echo "</script>\n"; 
                return true; 
            }  

	function pdfPrint()
	{
		$tax1tot=0;
		$discountTot=0;
		$cuId =$this->uri->segment(3, 0);
		$invoice = $this->model_pdf->getLemburDetail($cuId);
		
		$mataUang = $invoice['currency'];
		$idCustomer = $this->uri->segment(5, 0);
		$dateNow = $invoice['currency'];
		$sales = $this->uri->segment(4, 0);
		$delivDate = $this->uri->segment(8, 0);
		$shipto = $this->uri->segment(9, 0);
		$billto = $this->uri->segment(10, 0);
		$delivTerm = $this->uri->segment(11, 0);
		$payTerm = $this->uri->segment(12, 0);
		$Ptname = $this->uri->segment(13, 0);
		$orderno = $this->uri->segment(14, 0);
		$mode = $this->uri->segment(15, 0);
		//$ptDetail =  $this->model_pdf->getPtDetail($Ptname);
		$Ptnamebesar = $invoice['pt_name'];
		$Ptnamebesar = strtoupper($Ptnamebesar);
		$creator= get_username($this->session->userdata("emplo_id"));
		/*$custDet = $this->model_pdf->getCustomerDetail($idCustomer);
		$salesPerson= $this->model_pdf->getDriverDetail($sales);
		$billdetail = $this->model_pdf->getBillDetail($billto);
		$delivdetail = $this->model_pdf->getDelivDetail($shipto);*/
		$note = $this->model_pdf->getNote($cuId);
		$itemList = $this->model_pdf->getItemListLembur($cuId);
		$t2=0.00;
		$totalReal=0.00;
		$tax2=0.00;
		$subharga=0.00;
		$hitung=1;
		$subshow=0.00;
		$discountshow=0.00;
		$t1show=0.00;
		$t2show=0.00;
		$realshow=0.00;
		$hargabayar = number_format($invoice['total'], 0, ',', '.'); 
		$hargabayargaji = number_format($invoice['bayar'], 0, ',', '.'); 
		/*header("Content-type:application/pdf");
		header('Content-Disposition: attachment; filename="' . $cuId . '.pdf"');*/
		
		$this->load->library('cezpdf');
		//$this->load->library('cezpdf', array('paper' => 'a4','orientation' => 'potrait'));
		$this->load->helper('pdf_helper');	
		/*$datacreator = array (
                    'Title'=>'Invoice',
                    'Author'=>'Harpa',
                    'Subject'=>'Harpa Invoice',
                    'Creator'=>'Darius Sandatinus',
                    'Producer'=>'http://www.maestroglobal.biz'
                    );
		$this->cezpdf->addInfo($datacreator);
		*/
		

		/*$content = 'PT Harpa Sekawan
					Jl. Cipinang Muara No. 47
					Jakarta 13420';

		$this->cezpdf->ezText($content, 10, "justification('right')");*/
		//$this->cezpdf->addPngFromFile(site_url("img/logo1.png"));
		//$img = $this->cezpdf->ezImage("C:\\xampp\htdocs\harpa\img\log2.jpg");
		
		
		$data = array(
			array('img'=>$this->cezpdf->ezImage("C:\\xampp\htdocs\harpa\img\log2.jpg",0,120,"none",0),'name'=>'<b>PT HARPA SEKAWAN</b>','type'=>'')
			,array('img'=>'','name'=>'Jl Cipinang Muara No. 47','type'=>'Creator: ' . $creator)
			,array('img'=>'','name'=>'Jakarta 13420','type'=>'')
			
			,array('img'=>'','name'=>'Tel: +6221 8195784  Fax:  +6221 8502527','type'=>'')
			,array('img'=>'','name'=>'Email: info@harpa.co.id','type'=>'Invoice No: '. $cuId)
			,array('img'=>'','name'=>'Website: www.harpa.co.id','type'=>'Currency: ' .$mataUang)
		);
		
		$this->cezpdf->ezTable($data
								,array('img'=>'','name'=>'','type'=>''),''
								,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>500.200, 'col'=>array('justification'=>'right')));
		$this->cezpdf->setLineStyle(3, 'round');						
		$this->cezpdf->line(30,665,370,665);
		$this->cezpdf->addText(380,662,14,'Lembur');
		$this->cezpdf->line(430,665,570,665);
		
		$data1 = array(
			array('name'=>'','type'=>'')
		
			,array('name'=>'','type'=>'')
			,array('name'=>'','type'=>'')
			,array('name'=>'Dibayar Kepada','type'=>'Tagihan Kepada')
			,array('name'=>'Bpk. ' .$invoice['name'],'type'=>'Mr./Ms. ' . $invoice['customer_name'])
			,array('name'=>'Company: PT Harpa Sekawan','type'=>'Company : '.$Ptnamebesar)
			,array('name'=>'Uang Sejumlah : Rp.'.$hargabayar,'type'=>'')
			,array('name'=>'Periode : '.$invoice['invo_date'] .' - ' .$invoice['delivdate'],'type'=>'')
			,array('name'=>'' ,'type'=>'')
			
		);
		$this->cezpdf->ezTable($data1
								,array('name'=>'','type'=>''),''
								,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>530.28));
		
		/*$data2 = array(
			array('name'=>'Date','type'=>$dateNow, '3'=>'Order No', '4'=>$orderno,'5'=>'Sales Person', '6'=>$salesPerson)
		
			,array('name'=>'Delivery Date','type'=>$delivDate, '3'=>'Delivery Term', '4'=>$delivTerm,'5'=>'Terms', '6'=>$payTerm . ' Hari')
			
		);
		$this->cezpdf->ezTable($data2
								,array('name'=>'','type'=>'','3'=>'','4'=>'','5'=>'','6'=>''),''
								,array('showHeadings'=>0, 'showLines'=>2,'shaded'=>1,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>530.28));*/
		
		$data4 = array(
			
			array('name'=>'','type'=>'')
			
			
		);
		$this->cezpdf->ezTable($data4
								,array('name'=>'','type'=>''),''
								,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>400.28, 'col'=>array('justification'=>'right')));
										
		$data3 = array();
		if($itemList==""){}
		else{
			foreach($itemList as $itemList1){
				array_push($data3,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', 'tax1'=>'', 'tax2'=>'', '7'=>''));
			}
			
			foreach($itemList as $itemList1){
				$hitung++;
			}
			
			$data3 = array();
			$i=1;
			foreach($itemList as $itemList1){
				$discount = $itemList1['harga']*$itemList1['disc']/100;
				$harga = $itemList1['harga'] - $discount;
				$harga = $harga * $itemList1['prd'];
				if(($itemList1['tax1']=="on")&&($itemList1['tax2']=="on")){
					$hargatotal = ($harga*1.05)*1.1;
					$tax2= $harga *0.05;
					$tax1= ($tax2+$harga) *0.1;
					$tax1stat = "Y";
					$tax2stat = "Y";
				}
				else if(($itemList1['tax1']=="on")&&($itemList1['tax2']=="0")){
					$hargatotal = $harga*1.1;
					$tax1= $harga *0.1;
					$tax2= 0;
					$tax1stat = "Y";
					$tax2stat = "N";
				}
				else if(($itemList1['tax1']=="0")&&($itemList1['tax2']=="on")){
					$hargatotal = $harga*1.02;
					$tax1= 0;
					$tax2= $harga *0.02;
					$tax1stat = "N";
					$tax2stat = "Y";
				}
				else{
					$hargatotal = $harga;
					$tax1= 0;
					$tax2= 0;
					$tax1stat = "N";
					$tax2stat = "N";
				}
				$hargashow = number_format($hargatotal, 0, ',', '.'); 
				$discshow =  number_format($discount, 0, ',', '.'); 
				$harga1show = number_format($itemList1['harga'], 0, ',', '.');
				$discountTot = $discountTot + $discount;
				$subharga = $subharga + $itemList1['harga']*$itemList1['prd'];
				$tax1tot = $tax1tot+$tax1;
				$t2=$t2+$tax2;
				$totalReal = $totalReal+$hargatotal;
				$tax1show = number_format($tax1, 0, ',', '.'); 
				$tax2show = number_format($tax2, 0, ',', '.');
				$subshow = number_format($subharga, 2, ',', '.');
				$t1show = number_format($tax1tot, 2, ',', '.');
				$t2show = number_format($t2, 2, ',', '.'); 
				$realshow = number_format($totalReal, 2, ',', '.'); 
				$discountshow = number_format($discountTot, 2, ',', '.');  
				
				array_push($data3,array('name'=>$i,'type'=>$itemList1['brg_id'], '3'=>$itemList1['desc'], '4'=>$harga1show,'5'=>$itemList1['prd'], '6'=>$discshow, 'tax1'=>$tax1show,'tax2'=>$tax2show, '7'=>$hargashow));
				
				
				
				//$totalReal = $totalReal + $hargatotal;
				$i++;
			}
		}//end of if itemlist kosong
		if($hitung<13){
			for($hitung=$hitung; $hitung<13; $hitung++){
				array_push($data3,array('name'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', 'tax1'=>'','tax2'=>'', '7'=>''));
			}
		}
			/*array('name'=>'1','type'=>'CAR15', '3'=>'Mobil pemilik: Blue Star Toyota Vios Silver', '4'=>'1,500,000','5'=>'1', '6'=>'88,000', '7'=>'1,380,000')*/
			
			
		$this->cezpdf->ezTable($data3
								,array('name'=>'No.','3'=>'SKU/Deskripsi','4'=>'Unit Price','5'=>'Qty','6'=>'Disc', 'tax1'=>'Fee 5%', 'tax2'=>'Ppn 10%', '7'=>'Amount'),''
								,array('showHeadings'=>1, 'showLines'=>1,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>530.28));
										
		$this->cezpdf->ezSetDy(-8);
		
		$this->cezpdf->ezText('Note : ', '10');			
		$this->cezpdf->ezText($invoice['note'], '10');
		if($subshow==0){$subshow="0.00";}
		if($t2show==0){$t2show="0.00";}
		if($t1show==0){$t1show="0.00";}
		if($realshow==0){$realshow="0.00";}
		
		$this->cezpdf->addTextWrap('330','230','100','10','Subtotal:','right','0');
		$this->cezpdf->addTextWrap('460','230','100','10',$subshow,'right','0');
		$this->cezpdf->addTextWrap('330','215','100','10','Fee (5%):','right','0');
		$this->cezpdf->addTextWrap('460','215','100','10',$t2show,'right','0');
		$this->cezpdf->addTextWrap('330','200','100','10','PPN (10%):','right','0');
		$this->cezpdf->addTextWrap('460','200','100','10',$t1show,'right','0');
		
				
		$this->cezpdf->setLineStyle(1);						
		$this->cezpdf->line(360,190,560,190);		
		$this->cezpdf->addTextWrap('330','175','100','10','<b>Total:</b>','right','0');
		$this->cezpdf->addTextWrap('460','175','100','10',$realshow,'right','0');	
		
		$this->cezpdf->addTextWrap('40','130','100','10','Authorized Signature,','left','0');
		$this->cezpdf->line(40,35,180,35);	
		//prep_pdf(); 
					
		//print $this->cezpdf->output();
		//echo "<meta http-equiv='Refresh' content='0; URL=/'>";
		
				
		$nama =  $cuId . "-Form Lembur(Untuk Customer)-" . $invoice['pt_name']. "-". $invoice['name'].".pdf";
			$filename = '/invoice harpa/'.date("d F Y") . '/' . $nama;
			$dirname = dirname($filename);
			if (!is_dir($dirname))
			{
				mkdir($dirname, 0755, true);
			}
			$fp=fopen($filename,'wb');
			fwrite($fp,$this->cezpdf->ezOutput());
			fclose($fp);
			
			
		//	$this->load->library('cezpdf');
		//$this->load->library('cezpdf', array('paper' => 'a4','orientation' => 'potrait'));
		//$this->load->helper('pdf_helper');	
		/*$datacreator = array (
                    'Title'=>'Invoice',
                    'Author'=>'Harpa',
                    'Subject'=>'Harpa Invoice',
                    'Creator'=>'Darius Sandatinus',
                    'Producer'=>'http://www.maestroglobal.biz'
                    );
		$this->cezpdf->addInfo($datacreator);
		*/
		
		$pdf = new Cezpdf(); 
		/*$content = 'PT Harpa Sekawan
					Jl. Cipinang Muara No. 47
					Jakarta 13420';

		$this->cezpdf->ezText($content, 10, "justification('right')");*/
		//$this->cezpdf->addPngFromFile(site_url("img/logo1.png"));
		//$img = $this->cezpdf->ezImage("C:\\xampp\htdocs\harpa\img\log2.jpg");
		
		
		$data = array(
			array('img'=>$pdf->ezImage("C:\\xampp\htdocs\harpa\img\log2.jpg",0,120,"none",0),'name'=>'<b>PT HARPA SEKAWAN</b>','type'=>'')
			,array('img'=>'','name'=>'Jl Cipinang Muara No. 47','type'=>'Creator: ' . $creator)
			,array('img'=>'','name'=>'Jakarta 13420','type'=>'')
			
			,array('img'=>'','name'=>'Tel: +6221 8195784  Fax:  +6221 8502527','type'=>'')
			,array('img'=>'','name'=>'Email: info@harpa.co.id','type'=>'Invoice No: '. $cuId)
			,array('img'=>'','name'=>'Website: www.harpa.co.id','type'=>'Currency: ' .$mataUang)
		);
		
		$pdf->ezTable($data
								,array('img'=>'','name'=>'','type'=>''),''
								,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>500.200, 'col'=>array('justification'=>'right')));
		$pdf->setLineStyle(3, 'round');						
		$pdf->line(30,665,370,665);
		$pdf->addText(380,662,14,'Lembur');
		$pdf->line(430,665,570,665);
		
		$data1 = array(
			array('name'=>'','type'=>'')
		
			,array('name'=>'','type'=>'')
			,array('name'=>'','type'=>'')
			,array('name'=>'Dibayar Kepada','type'=>'Tagihan Kepada')
			,array('name'=>'Bpk. ' .$invoice['name'],'type'=>'Mr./Ms. ' . $invoice['customer_name'])
			,array('name'=>'Company: PT Harpa Sekawan','type'=>'Company : '.$Ptnamebesar)
			,array('name'=>'Uang Sejumlah : Rp.'.$hargabayargaji,'type'=>'')
			,array('name'=>'Periode : '.$invoice['invo_date'] .' - ' .$invoice['delivdate'],'type'=>'')
			,array('name'=>'' ,'type'=>'')
			
		);
		$pdf->ezTable($data1
								,array('name'=>'','type'=>''),''
								,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>530.28));
		
				
		$data4 = array(
			
			array('name'=>'','type'=>'')
			
			
		);
		$pdf->ezTable($data4
								,array('name'=>'','type'=>''),''
								,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>400.28, 'col'=>array('justification'=>'right')));
										
		$data3 = array();
		$hitung=0;
		$subharga=0;
		if($itemList==""){}
		else{
			foreach($itemList as $itemList1){
				array_push($data3,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', 'tax1'=>'', 'tax2'=>'', '7'=>''));
			}
			
			foreach($itemList as $itemList1){
				$hitung++;
			}
			
			$data3 = array();
			$i=1;
			foreach($itemList as $itemList1){
				$discount = $itemList1['harga']*$itemList1['disc']/100;
				$harga = $itemList1['harga'] - $discount;
				$harga = $harga * $itemList1['prd'];
				if(($itemList1['tax1']=="on")&&($itemList1['tax2']=="on")){
					$hargatotal = $harga;
					$tax1= 0;
					$tax2= 0;
					$tax1stat = "Y";
					$tax2stat = "Y";
				}
				else if(($itemList1['tax1']=="on")&&($itemList1['tax2']=="0")){
					$hargatotal = $harga*1.1;
					$tax1= $harga *0.1;
					$tax2= 0;
					$tax1stat = "Y";
					$tax2stat = "N";
				}
				else if(($itemList1['tax1']=="0")&&($itemList1['tax2']=="on")){
					$hargatotal = $harga*1.02;
					$tax1= 0;
					$tax2= $harga *0.02;
					$tax1stat = "N";
					$tax2stat = "Y";
				}
				else{
					$hargatotal = $harga;
					$tax1= 0;
					$tax2= 0;
					$tax1stat = "N";
					$tax2stat = "N";
				}
				$hargashow = number_format($hargatotal, 0, ',', '.'); 
				$discshow =  number_format($discount, 0, ',', '.'); 
				$harga1show = number_format($itemList1['harga'], 0, ',', '.');
				$discountTot = $discountTot + $discount;
				$subharga = $subharga + $itemList1['harga']*$itemList1['prd'];
				$subreal = $subharga-$invoice['hutang'];
				$tax1tot = $tax1tot+$tax1;
				$t2=$t2+$tax2;
				$totalReal = $totalReal+$hargatotal;
				
				$t1show = number_format($tax1tot, 2, ',', '.');
				$t2show = number_format($t2, 2, ',', '.'); 
				$realshow = number_format($totalReal, 2, ',', '.'); 
				$discountshow = number_format($discountTot, 2, ',', '.');  
				
				array_push($data3,array('name'=>$i,'type'=>$itemList1['brg_id'], '3'=>$itemList1['desc'], '4'=>$harga1show,'5'=>$itemList1['prd'],'7'=>$hargashow));
				
				
				
				//$totalReal = $totalReal + $hargatotal;
				$i++;
			}
		}//end of if itemlist kosong
		if($hitung<13){
			for($hitung=$hitung; $hitung<13; $hitung++){
				array_push($data3,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'',  '7'=>''));
			}
		}
			/*array('name'=>'1','type'=>'CAR15', '3'=>'Mobil pemilik: Blue Star Toyota Vios Silver', '4'=>'1,500,000','5'=>'1', '6'=>'88,000', '7'=>'1,380,000')*/
			
			
		$pdf->ezTable($data3
								,array('name'=>'No.','type'=>'ID','3'=>'SKU/Deskripsi','4'=>'Unit Price','5'=>'Qty', '7'=>'Amount'),''
								,array('showHeadings'=>1, 'showLines'=>1,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>530.28));
										
		$pdf->ezSetDy(-8);
		
		$pdf->ezText('Note : ', '10');			
		$pdf->ezText($invoice['note'], '10');
		if($subshow==0){$subshow="0.00";}
		if($t2show==0){$t2show="0.00";}
		if($t1show==0){$t1show="0.00";}
		if($realshow==0){$realshow="0.00";}
		
		/*$pdf->addTextWrap('330','230','100','10','Subtotal:','right','0');
		$pdf->addTextWrap('460','230','100','10',$subshow,'right','0');
		*/
		
		$subrealshow = number_format($subharga, 2, ',', '.');
		$subshow = number_format($subreal, 2, ',', '.');
		$hutang = number_format($invoice['hutang'], 2, ',', '.');
		$pdf->addTextWrap('330','175','100','10','<b>Subtotal:</b>','right','0');
		$pdf->addTextWrap('460','175','100','10',$subrealshow,'right','0');	
		$pdf->addTextWrap('330','160','100','10','<b>Potongan Hutang:</b>','right','0');
		$pdf->addTextWrap('460','160','100','10',$hutang,'right','0');	
				
		$pdf->setLineStyle(1);						
		$pdf->line(360,145,560,145);		
		$pdf->addTextWrap('330','130','100','10','<b>Total:</b>','right','0');
		$pdf->addTextWrap('460','130','100','10',$subshow,'right','0');	
		
		$pdf->addTextWrap('40','120','100','10','Authorized Signature,','left','0');
		$pdf->line(40,35,180,35);	
		//prep_pdf(); 
					
		//print $pdf->output();
		//echo "<meta http-equiv='Refresh' content='0; URL=/'>";
		
				
		$nama =  $cuId . "-Form Lembur(Untuk Driver)-" . $invoice['pt_name']. "-". $invoice['name'].".pdf";
			$filename = '/invoice harpa/'.date("d F Y") . '/' . $nama;
			$dirname = dirname($filename);
			if (!is_dir($dirname))
			{
				mkdir($dirname, 0755, true);
			}
			$fp=fopen($filename,'wb');
			fwrite($fp,$pdf->ezOutput());
			fclose($fp);

			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		if($mode=="edit"){
			redirect("/driver/lembur/set");
		}else{
			redirect("/invoice/add_invoice/set");
		}
	}
	
	function pdfMultiPrint()
	{
		$mulai = $this->uri->segment(3, 0)+4;
		$this->load->library('cezpdf');
			//$this->load->library('class.pdf');
						//$this->load->library('cezpdf', array('paper' => 'a4','orientation' => 'potrait'));
		$this->load->helper('pdf_helper');	
		for($j=4; $j<$mulai; $j++){
			$invoice_no = $this->uri->segment($j, 0);
			$invoice = $this->model_pdf->getLemburDetail($invoice_no);
			
		 	$cuId =$invoice_no;
			$mataUang = $invoice['currency'];
			$idCustomer = $invoice['cust_id'];
			$dateNow = $invoice['invoice_date'];
			$sales = $invoice['salesid'];
			$delivDate = $invoice['delivdate'];
			$shipto = $invoice['deliv'];
			$billto = $invoice['bill'];
			$delivTerm = $invoice['delivterms'];
			$payTerm = $invoice['term'];
			$Ptname = $invoice['pt_id'];
			$orderno = $invoice['orderno'];
			$ptDetail =  $this->model_pdf->getPtDetail($Ptname);
			$Ptnamebesar = $ptDetail['pt_name'];
			$Ptnamebesar = strtoupper($Ptnamebesar);
			$creator= get_username($this->session->userdata("user_id"));
			$salesPerson= get_username($sales);
			$billdetail = $this->model_pdf->getBillDetail($billto);
			//$drivDetail = $this->model_pdf->getBillDetail($drivTo);
			$delivdetail = $this->model_pdf->getDelivDetail($shipto);
			$note = $this->model_pdf->getNote($cuId);
			$itemList = $this->model_pdf->getItemList($cuId);
			$t2=0;
			$totalReal=0.00;
			$tax2=0;
			$subharga=0;
			$hitung=1;
			$tax1tot=0;
			$discountTot=0;
			$subshow=100.00;
			$discountshow=0.00;
			$t1show=100.00;
			$t2show=100.00;
			$realshow=0.00;			/*header("Content-type:application/pdf");
			header('Content-Disposition: attachment; filename="' . $cuId . '.pdf"');*/
			
			$pdf = new Cezpdf(); 
			/*$datacreator = array (
						'Title'=>'Invoice',
						'Author'=>'Harpa',
						'Subject'=>'Harpa Invoice',
						'Creator'=>'Darius Sandatinus',
						'Producer'=>'http://www.maestroglobal.biz'
						);
			$pdf->addInfo($datacreator);*/
			
			
			
			$data = array(
				array('name'=>'<b>PT HARPA SEKAWAN</b>','type'=>'')
				,array('name'=>'Jl Cipinang Muara No. 47','type'=>'')
				,array('name'=>'Jakarta 13420','type'=>'')
				,array('name'=>'','type'=>'')
				,array('name'=>'','type'=>'')
				,array('name'=>'Tel: +6221 8195784  Fax:  +6221 8502527','type'=>'')
				,array('name'=>'Email: info@harpa.co.id','type'=>'Invoice No: '. $cuId)
				,array('name'=>'Website: www.harpa.co.id','type'=>'Currency: ' .$mataUang)
			);
			$pdf->ezTable($data
									,array('name'=>'','type'=>''),''
									,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
											,'xOrientation'=>'left','width'=>400.28, 'col'=>array('justification'=>'right')));
			$pdf->setLineStyle(3, 'round');						
			$pdf->line(30,665,370,665);
			$pdf->addText(380,662,14,'Lembur');
			$pdf->line(430,665,570,665);
		
			$data1 = array(
				array('name'=>'','type'=>'')
			
				,array('name'=>'','type'=>'')
				,array('name'=>'','type'=>'')
				,array('name'=>'Di Bayar Kepada','type'=>'Delivery To')
				,array('name'=>'Bpk. ' .$invoice['name'],'type'=>'Mr./Ms. ' . $delivdetail['0']['ship_name'])
				,array('name'=>$Ptnamebesar,'type'=>$Ptnamebesar)
				,array('name'=>$billdetail['0']['bill_alamat'] . '   RT.0' . $billdetail['0']['bill_rt'] 
						. '   RW.0' . $billdetail['0']['bill_rw']
						,'type'=>$delivdetail['0']['ship_alamat'] . '   RT.0' . $delivdetail['0']['ship_rt'] 
						. '   RW.0' . $delivdetail['0']['ship_rw'])
				,array('name'=>$billdetail['0']['bill_kota'],'type'=>$delivdetail['0']['ship_kota'])
				,array('name'=>$billdetail['0']['bill_provinsi'] . ' - ' . $billdetail['0']['bill_kode']
						,'type'=>$delivdetail['0']['ship_provinsi'] . ' - ' . $delivdetail['0']['ship_kode'])
				,array('name'=>'','type'=>'')
				,array('name'=>'Phone: ' . $billdetail['0']['bill_telp'] . '    Fax: ' . $billdetail['0']['bill_fax']
						,'type'=>'Phone: ' . $delivdetail['0']['ship_telp']. '   Fax: '. $delivdetail['0']['ship_fax'])
				
			);
			$pdf->ezTable($data1
									,array('name'=>'','type'=>''),''
									,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
											,'xOrientation'=>'left','width'=>530.28));
			
			$data2 = array(
				array('name'=>'Date','type'=>$dateNow, '3'=>'Order No', '4'=>$orderno,'5'=>'Sales Person', '6'=>$salesPerson)
			
				,array('name'=>'Delivery Date','type'=>$delivDate, '3'=>'Delivery Term', '4'=>$delivTerm,'5'=>'Terms', '6'=>$payTerm . ' Hari')
				
			);
			$pdf->ezTable($data2
									,array('name'=>'','type'=>'','3'=>'','4'=>'','5'=>'','6'=>''),''
									,array('showHeadings'=>0, 'showLines'=>2,'shaded'=>1,'xPos'=>'right'
											,'xOrientation'=>'left','width'=>530.28));
		
			$data4 = array(
				
				array('name'=>'','type'=>'')
				
				
			);
			$pdf->ezTable($data4
									,array('name'=>'','type'=>''),''
									,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
											,'xOrientation'=>'left','width'=>400.28, 'col'=>array('justification'=>'right')));
											
			$data3 = array();
			if($itemList==""){
					$subshow = number_format($subharga, 2, ',', '.');
					$t1show = number_format($tax1tot, 2, ',', '.');
					$t2show = number_format($t2, 2, ',', '.'); 
					$realshow = number_format($totalReal, 2, ',', '.'); 
					$discountshow = number_format($discountTot, 2, ',', '.');  
			}
			else{
				foreach($itemList as $itemList1){
					array_push($data3,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', 'tax1'=>'', 'tax2'=>'', '7'=>''));
				}
			
				foreach($itemList as $itemList1){
					$hitung++;
				}
				
				$data3 = array();
				$i=1;
				foreach($itemList as $itemList1){
					$discount = $itemList1['harga']*$itemList1['disc']/100;
					$harga = $itemList1['harga'] - $discount;
					if(($itemList1['tax1']=="on")&&($itemList1['tax2']=="on")){
						$hargatotal = $harga*1.1*1.02;
						$tax1= $harga *0.1;
						$tax2= $harga *0.02;
						$tax1stat = "Y";
						$tax2stat = "Y";
					}
					else if(($itemList1['tax1']=="on")&&($itemList1['tax2']=="0")){
						$hargatotal = $harga*1.1;
						$tax1= $harga *0.1;
						$tax2= 0;
						$tax1stat = "Y";
						$tax2stat = "N";
					}
					else if(($itemList1['tax1']=="0")&&($itemList1['tax2']=="on")){
						$hargatotal = $harga*1.02;
						$tax1= 0;
						$tax2= $harga *0.02;
						$tax1stat = "N";
						$tax2stat = "Y";
					}
					else{
						$hargatotal = $harga;
						$tax1= 0;
						$tax2= 0;
						$tax1stat = "N";
						$tax2stat = "N";
					}
					$hargashow = number_format($hargatotal, 0, ',', '.'); 
					$discshow =  number_format($discount, 0, ',', '.'); 
					$harga1show = number_format($itemList1['harga'], 0, ',', '.');
					$discountTot = $discountTot + $discount;
					$subharga = $subharga + $itemList1['harga'];
					$tax1tot = $tax1tot+$tax1;
					$t2=$t2+$tax2;
					$totalReal = $totalReal+$hargatotal;
					$subshow = number_format($subharga, 2, ',', '.');
					$t1show = number_format($tax1tot, 2, ',', '.');
					$t2show = number_format($t2, 2, ',', '.'); 
					$realshow = number_format($totalReal, 2, ',', '.'); 
					$discountshow = number_format($discountTot, 2, ',', '.');  
					
					array_push($data3,array('name'=>$i,'type'=>$itemList1['brg_id'], '3'=>$itemList1['desc'], '4'=>$harga1show,'5'=>$itemList1['prd'], '6'=>$discshow, 'tax1'=>$tax1stat,'tax2'=>$tax2stat, '7'=>$hargashow));
					
					
					
					//$totalReal = $totalReal + $hargatotal;
					$i++;
				}//end of foreach
			}//end of if itemlist kosong
			if($hitung<10){
				for($hitung=$hitung; $hitung<11; $hitung++){
					array_push($data3,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', 'tax1'=>'','tax2'=>'', '7'=>''));
				}
			}
			/*array('name'=>'1','type'=>'CAR15', '3'=>'Mobil pemilik: Blue Star Toyota Vios Silver', '4'=>'1,500,000','5'=>'1', '6'=>'88,000', '7'=>'1,380,000')*/
			
			
			$pdf->ezTable($data3
									,array('name'=>'No.','type'=>'ID','3'=>'SKU/Deskripsi','4'=>'Unit Price','5'=>'Qty','6'=>'Disc', 'tax1'=>'T1', 'tax2'=>'T2', '7'=>'Amount'),''
									,array('showHeadings'=>1, 'showLines'=>1,'shaded'=>0,'xPos'=>'right'
											,'xOrientation'=>'left','width'=>530.28));
											
			$pdf->ezSetDy(-8);
			
			$pdf->ezText('Note : ', '10');			
			$pdf->ezText($note['0']['note'], '10');
		
			$pdf->addTextWrap('330','230','100','10','Subtotal:','right','0');
			$pdf->addTextWrap('460','230','100','10',$subshow,'right','0');
			$pdf->addTextWrap('330','215','100','10','Total Discount:','right','0');
			$pdf->addTextWrap('460','215','100','10',$discountshow,'right','0');	
			$pdf->addTextWrap('330','200','100','10','VAT/PPN (10%):','right','0');
			$pdf->addTextWrap('460','200','100','10',$t1show,'right','0');
			$pdf->addTextWrap('330','185','100','10','Withholding Tax(2%):','right','0');
			$pdf->addTextWrap('460','185','100','10',$t2show,'right','0');
					
			$pdf->setLineStyle(1);						
			$pdf->line(360,175,560,175);		
			$pdf->addTextWrap('330','160','100','10','<b>Total:</b>','right','0');
			$pdf->addTextWrap('460','160','100','10',$realshow,'right','0');	
			
			$pdf->addTextWrap('40','115','100','10','Authorized Signature,','left','0');
			$pdf->line(40,35,180,35);	
		//prep_pdf(); 
					
		//print $pdf->output();
		//echo "<meta http-equiv='Refresh' content='0; URL=/'>";
		
			
		//$pdfcode =
			$nama =  $cuId . ".pdf";
			$filename = '/invoice harpa/'.date("d F Y") . '/' . $nama;
			$dirname = dirname($filename);
			if (!is_dir($dirname))
			{
				mkdir($dirname, 0755, true);
			}
			$fp=fopen($filename,'wb');
			fwrite($fp,$pdf->ezOutput());
			fclose($fp);
			
				
		}//end of for
			
			
			
			
			
		
			redirect("/invoice/index/set");

	
			/*$content = 'PT Harpa Sekawan
						Jl. Cipinang Muara No. 47
						Jakarta 13420';
	
			$this->cezpdf->ezText($content, 10, "justification('right')");*/
		
		
	
	}
	function tables()
	{
		$this->load->library('cezpdf');

		$db_data[] = array('name' => 'Jon Doe', 'phone' => '111-222-3333', 'email' => 'jdoe@someplace.com');
		$db_data[] = array('name' => 'Jane Doe', 'phone' => '222-333-4444', 'email' => 'jane.doe@something.com');
		$db_data[] = array('name' => 'Jon Smith', 'phone' => '333-444-5555', 'email' => 'jsmith@someplacepsecial.com');
		
		$col_names = array(
			'name' => 'Name',
			'phone' => 'Phone Number',
			'email' => 'E-mail Address'
		);
		
		$this->cezpdf->ezTable($table_data, $col_names, 'Contact List', array('width'=>550));
		
		print $this->cezpdf->output();
	}

	
	function headers()
	{
		$this->load->library('cezpdf');
		$this->load->helper('pdf_helper');
		
		prep_pdf(); // creates the footer for the document we are creating.

		$db_data[] = array('name' => 'Jon Doe', 'phone' => '111-222-3333', 'email' => 'jdoe@someplace.com');
		$db_data[] = array('name' => 'Jane Doe', 'phone' => '222-333-4444', 'email' => 'jane.doe@something.com');
		$db_data[] = array('name' => 'Jon Smith', 'phone' => '333-444-5555', 'email' => 'jsmith@someplacepsecial.com');
		
		$col_names = array(
			'name' => 'Name',
			'phone' => 'Phone Number',
			'email' => 'E-mail Address'
		);
		
		$this->cezpdf->ezTable($db_data, $col_names, 'Contact List', array('width'=>550));
		$this->cezpdf->ezStream();
	}

}

?>